﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using IDML.BusinessObject;
using IDML.BusinessLogic;

namespace IDML.Web.Modules.Test
{
    public partial class AddTestFeeStruct : System.Web.UI.Page
    {
        TestBL testBL;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                PopulateTestCategoryLookup();
                PopulateTestLookup(Convert.ToInt32(ddlTestCategory.SelectedValue));
                Populate_gwTestFee(Convert.ToInt32(ddlTest.SelectedValue));
            }
        }

        public void PopulateTestCategoryLookup()
        {
            testBL = new TestBL();
            ddlTestCategory.DataSource = testBL.PopulateTestCategoryLookup();
            ddlTestCategory.DataValueField = "TestCategoryID";
            ddlTestCategory.DataTextField = "TestCategory";
            ddlTestCategory.DataBind();
        }

        public void PopulateTestLookup(int testCategoryID)
        {
            testBL = new TestBL();
            ddlTest.DataSource = testBL.PopulateTestLookup(testCategoryID);
            ddlTest.DataValueField = "TestID";
            ddlTest.DataTextField = "TestName";
            ddlTest.DataBind();
        }

        protected void ddlTestCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            PopulateTestLookup(Convert.ToInt32(ddlTestCategory.SelectedValue));
        }

        protected void btnTestAmount_Click(object sender, EventArgs e)
        {
            IDMLSession idmlSession = new IDMLSession();
            TestFeeStructureBO testfeestructBO = new TestFeeStructureBO();
            TestBL testBL = new TestBL();

            testfeestructBO.TestId = Convert.ToInt32(ddlTest.SelectedValue);
            testfeestructBO.Amount = Convert.ToDecimal(txtTestAmount.Text);
            testfeestructBO.IUserID = testfeestructBO.UUserID = Convert.ToInt32(idmlSession.User.UserID);

            testBL.TestFeeStructure_Save(testfeestructBO);
            Populate_gwTestFee(Convert.ToInt32(ddlTest.SelectedValue));
        }

        public void Populate_gwTestFee(int testID)
        {
            testBL = new TestBL();
            if (testBL.GetTestFeeStructurebyTestID(testID).Count != 0)
            {
                gwTestFee.DataSource = testBL.GetTestFeeStructurebyTestID(testID);
                gwTestFee.DataBind();
                dvgwTestFee.Visible = true;
            }
            else
            {
                dvgwTestFee.Visible = false;
            }

        }

        protected void ddlTest_SelectedIndexChanged(object sender, EventArgs e)
        {
            Populate_gwTestFee(Convert.ToInt32(ddlTest.SelectedValue));
        }
    }
}